<?php
namespace Common\ORG;
class Sentmsg {
    //private $url = 'http://web.mobset.com/SDK/Sms_Send.asp';
    private $url = 'http://sms.mobset.com/SDK2/Sms_Send.asp';
    private $lCorpID = '112741';
    private $strLoginName = "chen";
    private $strPasswd = "187801";

    const USER_AGENT = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36";
	/**
     * 架构函数
     * @access public
     * @param url  视频地址
     */
    // public function __construct($url) {
    //     $this->url    =   $url;
    // }

	//访问接口
	function curl_content($url, $timeout=10, $post_data=''){
		if(function_exists('curl_init')){
			$ch = curl_init();
			curl_setopt ($ch, CURLOPT_URL, $url);
			curl_setopt ($ch, CURLOPT_HEADER, 0);
			curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
			curl_setopt($ch,CURLOPT_USERAGENT,self::USER_AGENT);
			curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,$timeout);
			if($post_data){
				curl_setopt ($ch, CURLOPT_REFERER, $post_data);
			}
			$content = curl_exec($ch);
			curl_close($ch);
			if($content){
				return $content;
			}
		}
		return false;
	}

	public function sent($phone, $msg){
		$rmsg = array('rcode'=>0,'msg'=>'','data'=>NULL);
		if (!preg_match("/^1[34578]{1}\d{9}$/",$phone)){
			$rmsg['msg'] = '手机号码错误';
			return $rmsg;
		}
		if (strlen($msg) < 1) {
			$rmsg['msg'] = '短信为空';
			return $rmsg;
		}
		$vmsg = iconv("UTF-8", "GB2312//IGNORE", $msg); 
		$strTimeStamp = date('mdHis');
		$strInput = $this->lCorpID . $this->strPasswd . $strTimeStamp;
		$strMd5 = md5($strInput);
		$param = '?CorpID='.$this->lCorpID.'&LoginName='.$this->strLoginName.'&Passwd='.$strMd5;
		$param .= '&send_no='.$phone.'&Timer='.'&TimeStamp='.$strTimeStamp.'&msg='.rawurlencode($vmsg);
		$purl = $this->url.$param;
		$response = $this->curl_content($purl);
		$response = explode(',', $response);
		$rmsg['rcode'] = $response[0];
		$rmsg['msg'] = $response[1];
		return $rmsg;
	}




}